home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / wdj0797.zip / TUFFS.ZIP / EXCEPT7.CPP < prev    next >
C/C++ Source or Header  |  1997-04-24  |  765b  |  33 lines

  1. #include <iostream.h>
  2. #include <except.h>
  3. #include <cstring.h>
  4.  
  5. void badFunction(){
  6.   char *p = new char[100];
  7.   cout << "Setting p to zero..." << endl;
  8.   memset(p, 0, -10);
  9. }
  10. int main()
  11. {
  12.   for (int i=0; i<2; i++)
  13.   {
  14.     DWORD code = 0;
  15.     try
  16.     {
  17.       try
  18.       {
  19.         cout << "Calling badFunction()" << endl;
  20.         badFunction();
  21.         cout << "badFunction() completed without exception" << endl;
  22.       } catch (xmsg &x) {
  23.         cerr << "Exception caught '" << x.why() << "'" << endl;
  24.       } catch (...) {
  25.         cerr << "Unknown exception caught" << endl;
  26.       }
  27.     } __except (code=GetExceptionCode(), 1) {
  28.       cerr << "Unknown system exception " << hex << code << " caught" << endl;
  29.     }
  30.   }
  31.   return 0;
  32. }
  33.